package com.design;

import java.util.ArrayList;
import java.util.List;

/**
 * 群聊天
 */
public class GroupChat implements Chat{
    private List<User> users=new ArrayList<>();
    @Override
    public void sendMessage(String message, User user) {
        for(User u:users){
            if(u!=user){
                u.receiveMessage(user.getName(),message);
            }
        }
    }
    @Override
    public void addUser(User user) {
        System.out.println(user.getName()+",加入群聊");
        users.add(user);
    }
}
